package com.lz.gmall.product.controller;

import com.lz.gmall.common.result.Result;
import com.lz.gmall.common.result.ResultCodeEnum;
import com.lz.gmall.product.entity.BaseAttrInfo;
import com.lz.gmall.product.entity.BaseAttrValue;
import com.lz.gmall.product.service.BaseAttrInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
@Api(tags = "平台属性操作")
public class AttrInfoController {

    @Autowired
    private BaseAttrInfoService baseAttrInfoService;

    @ApiOperation("根据分类id获取平台属性")
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> getBaseAttrInfoPage(@PathVariable("category1Id") Long c1Id,
                                                          @PathVariable("category2Id") Long c2Id,
                                                          @PathVariable("category3Id") Long c3Id){

        List<BaseAttrInfo> baseAttrInfoList =  baseAttrInfoService.getBaseAttrInfoPage(c1Id,c2Id,c3Id);
        return Result.build(baseAttrInfoList, ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加 产品的平台属性和平台属性值
     * 修改 产品的平台属性和平台属性值
     * 添加和修改公用一个方法
     * @param baseAttrInfo 产品的平台属性和属性值信息
     */
    @PostMapping("/saveAttrInfo")
    @ApiOperation("添加/修改平台属性和属性值")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        baseAttrInfoService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }


}
